home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / ivecx.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  2KB  |  73 lines

  1. /*
  2.  *    Type specific routines for IntVec
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)ivecx.cc    2.1    8/18/89
  23.  */
  24.  
  25. #define NO_VECTOR_MATHFUN
  26. #include "rw/IntVec.h"
  27. #include "rw/FloatVec.h"
  28. #include "rw/DoubleVec.h"
  29.  
  30. // Convert to a DoubleVec
  31. // Should be a friend DoubleVec, but...
  32. IntVec::operator DoubleVec()
  33. {
  34.   register int n = length();
  35.   DoubleVec temp(n);
  36.   register double* dp = temp.data();
  37.   register int* tp = data();
  38.   register int ts = stride();
  39.   while(n--) {
  40.     *dp++ = double(*tp); tp += ts;
  41.   }
  42.   return temp;
  43. }
  44.  
  45. // Convert to a FloatVec
  46. // Should be a friend of FloatVec, but...
  47. IntVec::operator FloatVec()
  48. {
  49.   register int n = length();
  50.   FloatVec temp(n);
  51.   register float* dp = temp.data();
  52.   register int* tp = data();
  53.   register int ts = stride();
  54.   while(n--) {
  55.     *dp++ = float(*tp); tp += ts;
  56.   }
  57.   return temp;
  58. }
  59.  
  60. IntVec
  61. trunc(const DoubleVec& v)
  62. {
  63.   register int n = v.length();
  64.   IntVec temp(n);
  65.   register double* dp = v.data();
  66.   register int* ip = temp.data();
  67.   register int vs = v.stride();
  68.   while(n--) {
  69.     *ip++ = int(*dp); dp += vs;
  70.   }
  71.   return temp;
  72. }
  73.